package lablayer.model.MathComponents;

import lablayer.model.ComponentFactory;
import lablayer.model.Componentable;
import lablayer.model.LabData;

/**
 * @author Darkness
 */

class LeftBorder implements MathComponent {
    private LabData result;

    private LabData data;

    private String componentName = "Левая граница доверительного интервала";

    private String componentId = "7";

    public LeftBorder() {
        super();
        this.result = new LabData();
    }
    
    @Override
    public LabData getData() {
        return this.data;
    }

    @Override
    public void calculate() {
        Double[] row = this.data.getData()[0][0];
        Double value = 0.0;
        String rowString = "";

        Componentable middleValue = ComponentFactory.createComponent(
            MathComponentFactory.createMiddleValue());
        Componentable accuracyAssesment = ComponentFactory.createComponent(
            MathComponentFactory.createAccuracyAssessment());
        for (int i = 0; i < row.length; i++) {
            rowString += row[i];
            if (i != (row.length - 1)) {
                 rowString += ',';
            }
        }
        middleValue.setData(new LabData(LabData.parseString(rowString)));
        middleValue.calculate();
        accuracyAssesment.setData(this.data);
        accuracyAssesment.calculate();
        value = middleValue.getResult().getData()[0][0][0] - accuracyAssesment.
            getResult().getData()[0][0][0];
        this.result = new LabData(LabData.parseString(value.toString()));
    }

    @Override
    public void setData(LabData data) {
        if (data != null) {
            this.data = data;
        } else {
            throw new NullPointerException("Null pointer data");
        }
    }

    @Override
    public String getComponentId() {
        return this.componentId;
    }

    @Override
    public String getComponentName() {
        return this.componentName;
    }

    @Override
    public LabData getResult() {
        return this.result;
    }

	@Override
	public void setParameter(String params, String values) {
		throw new UnsupportedOperationException("Not supported yet.");
	}

	@Override
	public LabData getInitData() {
		throw new UnsupportedOperationException("Not supported yet.");
	}
}
